import request from '@/utils/request.js';
import {download, toFormData, checkDownloadRes} from '@/utils/common.js';

/**
 * 分页查询就业统计-就业数据文件
 */
export async function pageFiles(params) {
  const res = await request.get('/admin/employment/statistic/fileInfo/list', {params});
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询全部就业统计-就业数据文件
 */
export async function listFiles(params) {
  const res = await request.get('/statistic/file/list', {params});
  if (res.data.code === 200) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询就业统计-就业数据文件
 */
export async function getFile(id) {
  const res = await request.get('/statistic/file/' + id);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加就业统计-就业数据文件
 */
export async function addFile(data) {
  const res = await request.post('/statistic/file', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改就业统计-就业数据文件
 */
export async function updateFile(data) {
  const res = await request.put('/statistic/file', data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除就业统计-就业数据文件
 */
export async function removeFile(id) {
  const res = await request.delete('/statistic/file/' + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除就业统计-就业数据文件
 */
export async function removeFiles(ids) {
  const res = await request.delete('/statistic/file/' + ids.join());
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 导出就业统计-就业数据文件
 */
export async function exportFiles(params) {
  const res = await request({
    url: '/statistic/file/export',
    method: 'POST',
    data: toFormData(params),
    responseType: 'blob'
  });
  await checkDownloadRes(res);
  download(res.data, `file_${Date.now()}.xlsx`);
}


export async function importStudentInfoProgress(data) {
  const res = await request.get('/admin/employment/statistic/fileInfo/importDataProgress/' + data);
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}


export async function importStudentInfo(data) {
  const res = await request.post('/admin/employment/statistic/fileInfo/importData', data, {timeout: 300000});
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询报表信息
 */
export async function selectReportInfo() {
  const res = await request.get('/admin/finereport/info');
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}




